package com.fzy.hw_student.system.controller;


import com.fzy.hw_student.system.entity.SysRole;
import com.fzy.hw_student.system.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fzy
 * @since 2025-04-02
 */
@RestController
@RequestMapping("/system/sysRole")
public class SysRoleController {
    @Autowired
    ISysRoleService sysRoleService;

    @RequestMapping("/hello")
public String hello(){
    return "hello";
}
//页面调用controller层的接口方法，controller层的接口方法调用service层的接口方法，service层的接口方法调用dao层的接口方法。
    /**
     * 新增角色信息
     * @param sysRole SysRole
    * */
@PostMapping ("/addRole")

public String  addRole(@RequestBody SysRole sysRole){
        //相当于insert into sys_role(role_name,role_key,role_sort) values(?,?,?)
    sysRoleService.save(sysRole);
return "success";
}

    /**
     *删除角色信息
     * @param roleId Integer
     * @return String
     */
    @DeleteMapping ("/delRole/{roleId}")
    public String  delRole(@PathVariable Integer roleId){
        //相当于insert into sys_role(role_name,role_key,role_sort) values(?,?,?)
        sysRoleService.removeById(roleId);
        return "success";
    }

    /**
     *修改一个角色信息
     * @param roleId Integer
     */
    @PutMapping ("/updateRole")
    public String  updateRole(@RequestBody SysRole roleId){

        sysRoleService.updateById(roleId);
        return "success";
    }

/**
* 查询角色信息
 */
    @GetMapping ("/getRole/{roleId}")
    public SysRole getRole(@PathVariable Integer roleId){
        //相当于select * from sys_role where role_id=?
        SysRole sysRole = sysRoleService.getById(roleId);
       return sysRole;
    }

}
